package com.rs2hd.packethandler;

import com.rs2hd.model.ChatMessage;
import com.rs2hd.model.Player;
import com.rs2hd.GameEngine;
import com.rs2hd.net.Packet;
import com.rs2hd.util.Misc;
import org.apache.mina.common.IoSession;
/**
 * Chat packet handler.
 *
 * @author Graham
 */
public class ChatPacketHandler implements PacketHandler {
	@Override
	public void handlePacket(Player player, IoSession session, Packet packet) {
		if (player == null) {
			return;
		}
		int effects = packet.readShort();
		int numChars = packet.readShort();
		String text = Misc.decryptPlayerChat(packet, numChars);
		if (text.startsWith("::")) {
			//text = Misc.removeSlash(text);
			//GameEngine.ClanMain.clanMessage(player, text);
			new CommandPacketHandler().handlePacket(player, session, packet, text);
			return;
		}
		if (player.muted) {
			player.sm("You are currently muted.");
			return;
		}
		if (text.startsWith("/")) {
			text = Misc.removeSlash(text);
			GameEngine.ClanMain.clanMessage(player, text);
			return;
		}
		player.setLastChatMessage(new ChatMessage(effects, numChars, text));
		player.getUpdateFlags().setChatTextUpdateRequired(true);
	}
}
